﻿package com.bn.NNYY;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.media.MediaPlayer;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class GameView extends SurfaceView 
implements SurfaceHolder.Callback{
	
	MyActivity activity;
	Paint paint;//画笔
	
	FishingNet fishingnet;//渔网类的引用
	BackgroundPic backgroundpic;//背景图片类的引用
	Timer timer;//时间类的引用
	Score score;//得分类的引用
	MediaPlayer mMediaPlayer;//背景音乐播放器类
	
	int pointx;//触控到屏幕的位置，即渔网中心点坐标
	int pointy;//触控到屏幕的位置，即渔网中心点坐标
	
	float offsetx=0;//半透明窗口中心点，相对于触控到的中心点的距离
	float offsety=0;
	
	KeyThread keythread;//刷帧线程
	FishtailThread fishthread;//控制鱼尾摆动的线程
	FishGoThread fishgothread;//控制鱼走的线程
	FishGeneratorThread fishgeneratorthread;//产生鱼的线程
	CatchedFishtailThread catchedfishtailthread;//渔网中的鱼尾摆动的线程
	BackgroundPicThread backpicthread;//背景图片变换的线程
	TimeRunningThread timeruningthread;//负责倒计时的线程
	FishNetThread fishnetthread;//负责渔网图片变化的线程
	
	Bitmap fish1[];//第一组鱼的图片
	Bitmap fish2[];//第二组鱼的图片
	Bitmap fish3[];//第三组鱼的图片
	Bitmap fish_net[];//渔网图片
	Bitmap backg_round_pic[];//背景图片
	Bitmap board;//木板图片
	Bitmap fish_tank;//鱼缸图片
	Bitmap defen;//"得分"图片
	Bitmap number[];//“数字”图片
	Bitmap breakMarkBitmap;//时间分割符
	Bitmap bg_transparent;//半透明窗口的背景图片
	Bitmap bg_transparent1;//半透明窗口背景图片的红边
	
	ArrayList<SingleFish> afish=new ArrayList<SingleFish>();//生成鱼的类表
	ArrayList<SingleFish> del=new ArrayList<SingleFish>();//删除鱼的列表
	
	ArrayList<FishCatched> afishnet=new ArrayList<FishCatched>();//渔网上面的鱼
	ArrayList<FishCatched> delfishnet=new ArrayList<FishCatched>();//删除渔网上面的鱼
	
	public GameView(MyActivity activity) {
		super(activity);
		this.activity=activity;
		getHolder().addCallback(this);//注册回调接口
	}

	@Override
	public void onDraw(Canvas canvas)
	{
		super.onDraw(canvas);
		canvas.clipRect(new Rect(0,0,Constant.SCREEN_WIDTH,Constant.SCREEN_HEIGHT));//只在屏幕范围内绘制图片
		
		canvas.drawColor(Color.WHITE);//界面设置为白色		
		backgroundpic.drawSelf(canvas, paint);//绘制背景
		
		
		//绘制正常的鱼
		synchronized (afish) {
			for(SingleFish fish:afish)//绘制ArrayList中的每一条鱼
			{
				fish.drawSelf(canvas, paint,0,0);//后边的0,0为偏移量
			}
		}
		//绘制木板
		canvas.drawBitmap(board, 0, 7*Constant.SCREEN_HEIGHT/8, paint);
		//绘制鱼缸
		canvas.drawBitmap(fish_tank, 0, Constant.SCREEN_HEIGHT-Constant.FISHING_TANGK_HEIGHT, paint);
		//绘制渔网
		if(fishingnet.isDrawNetFlag())//绘制渔网的标志位为true时，绘制渔网
		{
			fishingnet.drawSelf(canvas, paint,0,0);//后边的0,0为偏移量
		}
		//绘制渔网上的鱼
		synchronized (afishnet) {
			for(FishCatched fish:afishnet)//绘制ArrayList中的每一条鱼
			{
				fish.drawSelf(canvas, paint,0,0);//后边的0,0为偏移量
			}
		}
		score.drawSelf(canvas, paint,0,0);//绘制“得分”和分数(后边的0,0为偏移量)
		timer.drawSelf(canvas, paint,0,0);//绘制时间(后边的0,0为偏移量)
		
		//绘制半透明窗口#########################开始绘制######################################
		if(fishingnet.isDrawNetFlag())//绘制渔网的标志位为true时，绘制半透明窗口
		{
			int x=0;
			int y=0;
			if(pointx>=0&&pointx<Constant.SCREEN_WIDTH/2&&
					pointy>=0&&pointy<Constant.SCREEN_HEIGHT/2)
			{//左上				
				x=Constant.TRANSPARENT_POSITION[3][0];
				y=Constant.TRANSPARENT_POSITION[3][1];
			}else if(pointx>=Constant.SCREEN_WIDTH/2&&pointx<=Constant.SCREEN_WIDTH&&
					pointy>=0&&pointy<Constant.SCREEN_HEIGHT/2)
			{//右上			
				x=Constant.TRANSPARENT_POSITION[2][0];
				y=Constant.TRANSPARENT_POSITION[2][1];
				
			}else if(pointx>=0&&pointx<Constant.SCREEN_WIDTH/2&&
					pointy>=Constant.SCREEN_HEIGHT/2&&pointy<=Constant.SCREEN_HEIGHT)
			{//左下			
				x=Constant.TRANSPARENT_POSITION[1][0];
				y=Constant.TRANSPARENT_POSITION[1][1];
			}else if(pointx>=Constant.SCREEN_WIDTH/2&&pointx<=Constant.SCREEN_WIDTH&&
					pointy>=Constant.SCREEN_HEIGHT/2&&pointy<=Constant.SCREEN_HEIGHT)
			{//右下				
				x=Constant.TRANSPARENT_POSITION[0][0];
				y=Constant.TRANSPARENT_POSITION[0][1];
			}

			offsetx=x+Constant.TRANSPARENT_WINDOW_WIDTH/2-pointx;
			offsety=y+Constant.TRANSPARENT_WINDOW_HEIGHT/2-pointy;
			canvas.save();
//			paint.setAlpha(100);
			canvas.clipRect(new Rect(x,y,x+Constant.TRANSPARENT_WINDOW_WIDTH,y+Constant.TRANSPARENT_WINDOW_HEIGHT));
			canvas.drawBitmap(bg_transparent, x, y, paint);//绘制背景
			
			//绘制正常的鱼
			synchronized (afish) {
				for(SingleFish fish:afish)//绘制ArrayList中的每一条鱼
				{
					fish.drawSelf(canvas, paint,offsetx,offsety);//后边的0,0为偏移量
				}
			}
			//绘制木板
			canvas.drawBitmap(board, 0+offsetx, 7*Constant.SCREEN_HEIGHT/8+offsety, paint);
			//绘制鱼缸
			canvas.drawBitmap(fish_tank, 0+offsetx, Constant.SCREEN_HEIGHT-Constant.FISHING_TANGK_HEIGHT+offsety, paint);
			
			//绘制渔网
			if(fishingnet.isDrawNetFlag())//绘制渔网的标志位为true时，绘制渔网
			{
				fishingnet.drawSelf(canvas, paint,offsetx,offsety);//后边的0,0为偏移量
			}
			
			//绘制渔网上的鱼
			synchronized (afishnet) {
				for(FishCatched fish:afishnet)//绘制ArrayList中的每一条鱼
				{
					fish.drawSelf(canvas, paint,offsetx,offsety);//后边的0,0为偏移量
				}
			}
			canvas.drawBitmap(bg_transparent1, x, y, paint);//绘制背景
//			paint.setAlpha(255);
			canvas.restore();			
		}
		//绘制半透明窗口#########################结束绘制######################################
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event)
	{
		pointx=(int) event.getX();
		pointy=(int) event.getY();
		switch(event.getAction())
		{
		case MotionEvent.ACTION_DOWN://按下
			fishingnet.setDrawNetFlag(true);//绘制渔网的标志位为true
			fishingnet.setCatchFishFlag(true);//可以捕鱼			
			fishingnet.getXandY(pointx, pointy);//当触控到屏幕的某一点时，计算渔网应该画在哪个位置
			break;
		case MotionEvent.ACTION_MOVE://移动
			fishingnet.setCatchFishFlag(false);//不可以捕鱼
			fishingnet.getXandY(pointx, pointy);//渔网跟着移动
			break;
		case MotionEvent.ACTION_UP://抬起
			fishingnet.setCatchFishFlag(false);//不可以捕鱼
			fishingnet.n=0;
			fishingnet.setDrawNetFlag(false);//绘制渔网的标志位为false
			break;
		}
		return true;
	}
	public void surfaceCreated(SurfaceHolder holder) {
		paint=new Paint();//创建画笔
		paint.setAntiAlias(true);//打开抗锯齿
		
		Constant.changeRadio();//调用常量类中常量赋值的方法
		initBitmap();//初始化位图资源
		//背景音乐
		mMediaPlayer=MediaPlayer.create(activity, R.raw.background);//创建背景音乐播放器
		mMediaPlayer.setLooping(true);//循环播放
		
		keythread=new KeyThread(this);//刷帧线程
		fishgeneratorthread=new FishGeneratorThread(this);//产生鱼的线程
		fishthread=new FishtailThread(this);//鱼尾摆动的线程，必须写在单个鱼的类后面
		fishgothread=new FishGoThread(this);//控制鱼走的线程
		catchedfishtailthread=new CatchedFishtailThread(this);//渔网中的鱼尾摆动的线程
		backpicthread=new BackgroundPicThread(this);//背景图片变化的线程
		timeruningthread=new TimeRunningThread(this);//负责倒计时的线程
		fishnetthread=new FishNetThread(this);
		
		fishingnet=new FishingNet(fish_net);//渔网类new对象
		backgroundpic=new BackgroundPic(backg_round_pic);//创建背景图片类的对象
		score=new Score(this,defen,number,breakMarkBitmap);//得分类的对象
		timer=new Timer(this,breakMarkBitmap,number);//时间类的对象
		
		//开启全部线程	
		startAllThreads();
		//开启背景音乐
		if(activity.backgroundsoundFlag)
		{
			mMediaPlayer.start();//开启音乐
		}
	}	
	public void judgeInFishingNet()//判断鱼是否在渔网内的方法
	{
		if(fishingnet.isDrawNetFlag()&&fishingnet.isFishNetIsBad()==false)//如果存在渔网(并且渔网完好)
		{//循环鱼的列表
			
			System.out.println("fishingnet.isFishNetIsBad()=="+fishingnet.isFishNetIsBad()+"  2222222222");
			
			synchronized (afish) {
				for(SingleFish fish:afish)
				{	//如果可以捕鱼的标志位为true，并且鱼在渔网内
					if(fishingnet.isCatchFishFlag()&&fish.x>pointx-Constant.FISHING_NET_WIDTH/2-Constant.FISHING_NET_WIDTH/2&&fish.x<pointx+Constant.FISHING_NET_WIDTH/2+Constant.FISHING_NET_WIDTH/2
							&&fish.y>pointy-Constant.FISHING_NET_HEIGHT/2-Constant.FISHING_NET_HEIGHT/2&&
							fish.y<pointy+Constant.FISHING_NET_HEIGHT/2+Constant.FISHING_NET_HEIGHT/2)
					{
						//首先在渔网的中间上面绘制一条新的鱼
						synchronized(afishnet)
						{
							FishCatched fishcatch=new FishCatched(fish.fish,
									pointx,pointy,fish.degrees,this,fish.space,fish.fishsign);//渔网上生成一条新的鱼
							afishnet.add(fishcatch);//在渔网上边绘制一条鱼
						}
						//将水中的鱼加入到，删除鱼的列表
						del.add(fish);
					}
				}
			}
		}else if(fishingnet.isFishNetIsBad())//如果渔网破损到不可以捕鱼
		{
			
			System.out.println("fishingnet.isFishNetIsBad()=="+fishingnet.isFishNetIsBad()+"  2222222222");
			
			
			synchronized(afishnet)
			{
				for(FishCatched delfish:afishnet)//循环渔网上鱼的列表
				{
					delfishnet.add(delfish);//将渔网上面的鱼加入到删除鱼的列表
					
					//将鱼重新放入水中
					synchronized(afish)
					{//否则绘制放回水中的鱼
						SingleFish fish=new SingleFish(delfish.fish,delfish.space+Constant.INCREACE_FISH_SPEED,
							delfish.x,delfish.y,delfish.degrees);//生成一条新的鱼
						afish.add(fish);	
					}
				}
				for(FishCatched fish:delfishnet)
				{
					afishnet.remove(fish);//删除渔网上的鱼的列表中的鱼
				}	
			}	
		}else//不存在渔网，删除渔网中的鱼
		{
			synchronized(afishnet)
			{
				for(FishCatched delfish:afishnet)//循环渔网上鱼的列表
				{
					delfishnet.add(delfish);//将渔网上面的鱼加入到删除鱼的列表
					
					//当渔网不存在时，即，将鱼重新放入水中（暂时的，今后还要改，还存在，将鱼放在鱼缸中的情况）
					synchronized(afish)
					{
						if(pointx>0&&pointx<100&&pointy>Constant.SCREEN_HEIGHT-100
								&&pointy<Constant.SCREEN_HEIGHT)//如果渔网中心点，到达鱼缸的位置
						{//将鱼放入了鱼缸中，得分增加
							if(delfish.fishsign==1)//如果是小鱼，得分加1
							{
								score.addScore(1);//得分增加
							}else if(delfish.fishsign==2)//如果是中间大的鱼得分加2
							{
								score.addScore(2);//得分增加
							}else if(delfish.fishsign==3)//如果是大鱼得分加3
							{
								score.addScore(3);//得分增加
							}
						}else//否则绘制放回水中的鱼
						{
							SingleFish fish=new SingleFish(delfish.fish,delfish.space+Constant.INCREACE_FISH_SPEED,
								delfish.x,delfish.y,delfish.degrees);//生成一条新的鱼
							afish.add(fish);
						}	
					}
				}
				for(FishCatched fish:delfishnet)
				{
					afishnet.remove(fish);//删除渔网上的鱼的列表中的鱼
				}	
			}
		}		
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		boolean retry = true;
		stopAllThreads();//停止所有线程
		
		//关闭所有线程
	    while (retry) {
	        try {
	        	fishgeneratorthread.join();
	        	fishthread.join();
	        	keythread.join();
	        	fishgothread.join();
	        	catchedfishtailthread.join();
	        	backpicthread.join();
	        	timeruningthread.join();
	        	fishnetthread.join();

	            retry = false;
	        } 
	        catch (InterruptedException e) {e.printStackTrace();}//不断地循环，直到其它线程结束
		}
	    
	    //关闭背景音乐
	    if(mMediaPlayer.isPlaying())//如果正在播放
	    {
	    	mMediaPlayer.stop();//停止播放
	    }
	}
	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
	}

	//初始化图片资源
	public void initBitmap(){
		//大鱼的图片
		fish1=new Bitmap[]{
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish11),Constant.BIG_FISH_WIDTH, Constant.BIG_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish10),Constant.BIG_FISH_WIDTH, Constant.BIG_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish11),Constant.BIG_FISH_WIDTH, Constant.BIG_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish12),Constant.BIG_FISH_WIDTH, Constant.BIG_FISH_HEIGHT)
			};
		fish2=new Bitmap[]{
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish21),Constant.MID_FISH_WIDTH, Constant.MID_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish20),Constant.MID_FISH_WIDTH, Constant.MID_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish21),Constant.MID_FISH_WIDTH, Constant.MID_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish22),Constant.MID_FISH_WIDTH, Constant.MID_FISH_HEIGHT)
		};
		fish3=new Bitmap[]{
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish31),Constant.SMALL_FISH_WIDTH, Constant.SMALL_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish30),Constant.SMALL_FISH_WIDTH, Constant.SMALL_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish31),Constant.SMALL_FISH_WIDTH, Constant.SMALL_FISH_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish32),Constant.SMALL_FISH_WIDTH, Constant.SMALL_FISH_HEIGHT)	
		};
		//渔网
		fish_net=new Bitmap[]{
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_net0), 
					Constant.FISHING_NET_WIDTH, Constant.FISHING_NET_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_net1), 
					Constant.FISHING_NET_WIDTH, Constant.FISHING_NET_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_net2), 
					Constant.FISHING_NET_WIDTH, Constant.FISHING_NET_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_net3), 
					Constant.FISHING_NET_WIDTH, Constant.FISHING_NET_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_net4), 
					Constant.FISHING_NET_WIDTH, Constant.FISHING_NET_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_net5), 
					Constant.FISHING_NET_WIDTH, Constant.FISHING_NET_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_net6), 
					Constant.FISHING_NET_WIDTH, Constant.FISHING_NET_HEIGHT)	
				
		};
		//背景图片
		backg_round_pic=new Bitmap[]{
//			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.background1), 
//					Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.background2), 
					Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.background3), 
					Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT),
			PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.background4), 
					Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT)
		};
		//半透明窗口图片
		bg_transparent=PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.bg_transparent0), 
				Constant.SCREEN_WIDTH/4, Constant.SCREEN_HEIGHT/4);
		bg_transparent1=PicLoadUtil.scaleToFit(BitmapFactory.decodeResource(this.getResources(), R.drawable.bg_transparent1), 
				Constant.SCREEN_WIDTH/4, Constant.SCREEN_HEIGHT/4);
		
		
		//木板图片
		board=BitmapFactory.decodeResource(this.getResources(), R.drawable.board);
		board=PicLoadUtil.scaleToFit(board, Constant.SCREEN_WIDTH, Constant.BOARD_HEIGHT);
		//鱼缸图片
		fish_tank=BitmapFactory.decodeResource(this.getResources(), R.drawable.fish_tank);
		fish_tank=PicLoadUtil.scaleToFit(fish_tank, Constant.FISHING_TANK_WIDTH, Constant.FISHING_TANGK_HEIGHT);
		//“得分”图片
		defen=BitmapFactory.decodeResource(this.getResources(), R.drawable.defen0);
		//“数字”图片
		number=new Bitmap[]{
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number0),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number1),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number2),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number3),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number4),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number5),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number6),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number7),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number8),
				BitmapFactory.decodeResource(this.getResources(), R.drawable.number9)
		};
		//时间分隔符
		breakMarkBitmap=BitmapFactory.decodeResource(this.getResources(), R.drawable.breakmark);
	}
	//结束游戏的方法
	public void overGame()
	{
		stopAllThreads();//停止所有线程
		
		//关闭背景音乐
	    if(mMediaPlayer.isPlaying())//如果正在播放
	    {
	    	mMediaPlayer.stop();//停止播放
	    }
		
		activity.sendMessage(2);//发送消息，进入游戏结束界面
	}
	//开启所有线程
	public void startAllThreads()
	{
		fishgeneratorthread.setFishgeneratorflag(true);//产生鱼的线程标志位设为true
		fishthread.setFlag(true);//鱼尾摆动线程标志位设为true
		keythread.setKeyFlag(true);//刷帧线程的标志位设为true
		fishgothread.setFishGoFlag(true);//鱼走线程的标志位设为true
		catchedfishtailthread.setFlag(true);//渔网中的鱼鱼尾摆动的线程标志位设为true
		backpicthread.setFlag(true);//背景图片变化的线程标志位设为true
		timeruningthread.setFlag(true);//倒计时的线程标志位为true
		fishnetthread.setFlag(true);//渔网图片变化的线程为true
		
		fishgeneratorthread.start();//开启产生鱼的线程
		fishthread.start();//开启鱼尾摆动的线程
		keythread.start();//开启刷帧线程
		fishgothread.start();//开启鱼走的线程
		catchedfishtailthread.start();//开启渔网中的鱼的鱼尾摆动的线程
		backpicthread.start();//开启背景图片变化的线程
		timeruningthread.start();//开启倒计时线程
		fishnetthread.start();//开启渔网变化的线程
	}
	//停止所有线程
	public void stopAllThreads()
	{
		fishingnet.setDrawNetFlag(false);//不可以绘制渔网
		fishingnet.setCatchFishFlag(false);//不可以捕鱼
		
		fishthread.setFlag(false);//关闭鱼尾摆动线程
		catchedfishtailthread.setFlag(false);//关闭渔网中的鱼尾摆动的线程
		backpicthread.setFlag(false);//关闭背景图片变化的线程
		timeruningthread.setFlag(false);//关闭倒计时线程
		keythread.setKeyFlag(false);//关闭刷帧线程
		fishgothread.setFishGoFlag(false);//关闭鱼走的线程
		fishgeneratorthread.setFishgeneratorflag(false);//关闭产生鱼的线程	
		fishnetthread.setFlag(false);//关闭渔网变化的线程
	}
	
	//重新绘制画面
	public void repaint()
	{
		Canvas canvas=this.getHolder().lockCanvas();
		try
		{
			synchronized(canvas)
			{
				onDraw(canvas);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}finally
		{
			if(canvas!=null)
			{
				this.getHolder().unlockCanvasAndPost(canvas);
			}
		}
	}

}
